/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 */

package com.huawei.api.cmd;

import com.huawei.api.bean.CmdExecResult;
import com.huawei.api.bean.CommandInfo;
import com.huawei.api.exception.InterruptException;

/**
 * 命令执行器
 *
 * @since 2023/10/28
 */
public abstract class BaseRunner {
    /**
     * 命令执行
     */
    protected CmdRunner cmdRunner;

    /**
     * 命令行对象
     */
    protected CommandInfo commandInfo;

    /**
     * 超时时间
     */
    protected int timeout = 1000;

    /**
     * 是否块
     */
    protected boolean isBlock;

    /**
     * BaseRunner构造函数
     */
    protected BaseRunner() {
        this.cmdRunner = new CmdRunner();
    }

    /**
     * 启动检查执行
     *
     * @return 执行检查结果
     * @throws Exception 异常
     */
    public abstract CmdExecResult run() throws InterruptException;

    /**
     * 释放内存
     *
     * @throws Exception 异常
     */
    public void release() throws InterruptException {
        cmdRunner.release();
        this.commandInfo = null;
    }
}
